﻿using System;
using System.Linq;
using EPiServer.Configuration;
using EPiServer.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TemplateFoundation.PageTypes;
using TemplateFoundation.Tests.Environment;
using TemplateFoundation.Core;

namespace TemplateFoundation.Tests.UnitTests.Core
{
    
    
    /// <summary>
    ///This is a test class for ExtensionsTest and is intended
    ///to contain all ExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ExtensionsTest
    {
        [TestMethod]
        public void TestGetCanonicalUrlWithoutSpecifyingAnyParameters()
        {
            var page = (PageTypeBase)PageStructure.CreateStandardPages("Page for canonical test", PageReference.RootPage, 1).First();

            var canonicalUrl = page.GetCanonicalUrl();

            Assert.AreEqual(page.LinkURL, canonicalUrl, "Canonical URL did not match page's relative URL");
        }

        [TestMethod]
        public void TestGetCanonicalUrlAsRelative()
        {
            var page = (PageTypeBase)PageStructure.CreateStandardPages("Page for canonical test", PageReference.RootPage, 1).First();

            var canonicalUrl = page.GetCanonicalUrl(false);

            Assert.AreEqual(page.LinkURL, canonicalUrl, "Canonical URL did not match page's relative URL");
        }

        [TestMethod]
        public void TestGetCanonicalUrlAsAbsolute()
        {
            var page = (PageTypeBase)PageStructure.CreateStandardPages("Page for canonical test", PageReference.RootPage, 1).First();

            var canonicalUrl = page.GetCanonicalUrl(true);

            Assert.AreEqual(Settings.Instance.SiteUrl.GetLeftPart(UriPartial.Authority) + page.LinkURL, canonicalUrl, "Canonical URL did not match page's relative URL");
        }

        [TestMethod]
        public void TestGetCanonicalUrlAsAbsoluteFriendlyUrl()
        {
            var page = (PageTypeBase)PageStructure.CreateStandardPages("Page for canonical test", PageReference.RootPage, 1).First();

            var canonicalUrl = page.GetCanonicalUrl(true, true);

            Assert.AreEqual(page.GetFriendlyUrl(true), canonicalUrl, "Canonical URL did not match page's absolute friendly URL");
        }

        [TestMethod]
        public void TestGetCanonicalUrlAsAbsoluteFullUrl()
        {
            var page = (PageTypeBase)PageStructure.CreateStandardPages("Page for canonical test", PageReference.RootPage, 1).First();

            var canonicalUrl = page.GetCanonicalUrl(false, true);

            Assert.AreEqual(page.GetFriendlyUrl(false), canonicalUrl, "Canonical URL did not match page's relative friendly URL");
        }
    }
}
